package com.dearbinge.im.service.impl.ofUser;

import com.dearbinge.data.api.ofUser.OfUserService;
import com.dearbinge.data.pojo.ofuser.Ofuser;
import com.dearbinge.im.dao.OfUserMapper;
import com.dearbinge.utils.date.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service(value = "ofUserService")
public class OfUserServiceImpl implements OfUserService {

    @Autowired
    private OfUserMapper ofUserMapper;

    @Override
    public Integer update(Ofuser ofuser) {
        Integer dataCode = ofUserMapper.update(ofuser);
        return dataCode;
    }

    @Override
    public Integer insert(Ofuser ofuser) {
        Ofuser ou = ofUserMapper.getByUserName(ofuser.getUsername());
        ofuser.setCreationdate("00"+new Date().getTime());
        ofuser.setModificationdate("00"+new Date().getTime());
        ofuser.setEmail(ofuser.getUsername()+"@example.com");
        Integer dataCode = 0;
        if (ou != null){
            dataCode = ofUserMapper.update(ofuser);
        }else {
            dataCode = ofUserMapper.insert(ofuser);
        }
        return dataCode;
    }
}
